package com.game.framework.common.error;

import org.slf4j.helpers.MessageFormatter;

public enum ServerErrorCode implements IServerErrorCode {
	SUCCESS(0,"连接成功"),
	UNKNOWN_ERROR(100,"未知错误"),
	TOKEN_ILLEGAL(101,"TOKEN非法"),
	TOKEN_EXPIRE(102,"TOKEN已过期"),
	REPEATED_CONNECT(103,"重复连接，可能异地登陆了"),
	ACCOUNT_NOT_EXIST(1000,"账号不存在"),
	PLAYER_NOT_EXIST(1001,"角色未创建"),
	PASSWORD_ERROR(1002,"密码输入错误"),
	PASSWORD_REPEATE_ERROR(10023,"重复输入错误密码"),
	SMS_CODE_ERROR(1004,"短信验证码错误"),
	RANK_TYPE_ERROR(1005,"排行榜类型错误"),
	ACTIVITY_FISH_NOT_EXIST(2000,"鱼塘没有鱼了"),
	ACTIVITY_BAIT_NOT_EXIST(2001,"你当前包袱中没有鱼饵了，请获得鱼饵后再来"),
	ACTIVITY_ROLE_NOT_EXIST(2002,"玩家还没有参与此活动"),
	ACTIVITY_ROLE_IS_FULL(2003,"超出人员限制 提示玩家 “已满员”"),
	;
	private int errorCode;
	private String errorMessage;

	private ServerErrorCode(int errorCode, String errorMessage) {
		this.errorCode = errorCode;
		this.errorMessage = errorMessage;
	}
	@Override
	public int getErrorCode() {
		return errorCode;
	}

	@Override
	public String getErrorMessage() {
		return errorMessage;
	}

	@Override
	public GameException newException() {
		String errorMsg = "errorCode:" + this.errorCode + "," + this.errorMessage;
		return new GameException(this, errorMsg);
	}

	public GameException newException(String format, Object... args) {
		if (args != null) {
			format = MessageFormatter.arrayFormat(format, args).getMessage();
		} else {
			format = "";
		}
		String errorMsg = "errorCode:" + this.errorCode + "," + this.errorMessage + "," + format;
		return new GameException(this, errorMsg);
	}

	@Override
	public String toString() {
		StringBuilder msg = new StringBuilder();
		msg.append("code:").append(this.errorCode).append("; msg:").append(this.errorMessage);
		return msg.toString();
	}
}
